<template>
  <div class="main">
    <el-card class="box-card">
      <div class="left">
        <!-- logo -->
        <div class="logo">
          <img src="@/assets/common/logo.png" alt="">
        </div>
        <!-- 表单 -->
        <div class="loginForm">
          <el-form
            ref="ruleForm"
            :model="ruleForm"
            :rules="rules"
            label-width="40px"
            hide-required-asterisk
            label-position="left"
          >
            <el-form-item label="账号" prop="username">
              <el-input
                v-model="ruleForm.username"
                prefix-icon="el-icon-mobile-phone"
              />
            </el-form-item>

            <el-form-item label="密码" prop="password">
              <el-input
                v-model="ruleForm.password"
                type="password"
                prefix-icon="el-icon-lock"
                show-password
              />
            </el-form-item>
          </el-form>
        </div>
        <!-- 多选框 -->
        <div class="remember">
          <el-checkbox v-model="checked">记住密码</el-checkbox>
        </div>
        <!-- 登录按钮 -->
        <el-button type="warning" @click="onLogin">立即登录</el-button>
      </div>
      <div class="right">
        <img
          src="@/assets/common/contentBg.png"
          alt=""
          width="560px"
          height="516px"
        >
      </div>
    </el-card>
  </div>
</template>

<script>
import { str } from '@/utils/index.js'
import { mapActions } from 'vuex'
export default {
  data() {
    return {
      ruleForm: {
        username: 'admin',
        password: '111111'
      },
      checked: true,
      rules: {
        username: [
          { required: true, message: '请输入账号', trigger: 'blur' },
          { min: 3, message: '长度在 3 个字符以上', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, message: '长度在 6 个字符以上', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  methods: {
    ...mapActions('user', ['login']),

    // 点击登录
    onLogin() {
      this.$refs.ruleForm.validate(async valid => {
        if (valid) {
          const result = await this.login(str)
          this.$message.success(result)
          this.$router.push('/')
        } else { return false }
      })
    }
  }
}
</script>
<style scoped lang="scss">
.main {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  .el-card {
    width: 958px;
    height: 516px;
    border-radius: 40px;
    ::v-deep .el-card__body {
      padding: 0;
      display: flex;
      height: 100%;
      .left {
        width: 398px;
        padding: 20px 40px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        .logo {
          margin: 30px 0px;
          text-align: center;
          img {
            width: 150px;
            height: 64px;
          }
        }
        .loginForm {
          margin-top: 30px;
        }
        .el-button {
          margin: 30px 0px;
        }
      }
      .right {
        width: 560px;
      }
    }
  }
}
// ::v-deep .el-form {
// }
</style>
